<template>
    <div class="detailsPage">
        <div class="top">
            <div style="font-size: 20px; cursor: pointer;" @click="$router.go(-1)">{{ this.list[0].product_name }}</div>
            <div class="div">
                <span>概述</span>
                <span>参数</span>
                <span>用户评价</span>
            </div>
        </div>
        <div class="center">
            <div class="left">
                <el-carousel indicator-position="outside" class="carousel" height="500px">
                    <el-carousel-item v-for="(item, index) in imglist" :key="index" class="carouselitem">
                        <img :src="'http://101.132.181.9/api/' + item.product_picture" alt="" class="img" >
                    </el-carousel-item>
                </el-carousel>
            </div>
            <div class="right">
                <h3 style="font-size: 28px;">{{ this.list[0].product_name }}</h3>
                <p class="text">{{ this.list[0].product_intro }}</p>
                <p class="p">小米自营</p>
                <div class="price">
                    <span>{{ this.list[0].product_selling_price }}元</span>
                    <s>{{ this.list[0].product_price }}</s>
                </div>
                <div class="ming">
                    <div class="ming-top">
                        <span>{{ this.list[0].product_name }}</span>
                        <span>
                            <span>{{ this.list[0].product_selling_price }}元</span>
                            <s style="font-size: 15px; margin-left: 10px;">{{ this.list[0].product_price }}元</s>
                        </span>
                    </div>
                    <div class="ming-button">总计：{{ this.list[0].product_selling_price }}元</div>
                </div>
                <div class="button">
                    <button class="a1" @click="addcat">加入购物车</button>
                    <button class="a2" @click="like">喜欢</button>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { imglist, goodsDetails, addcat,getlike } from '../api/api'
export default {
    data() {
        return {
            productID: this.$store.state.productID,
            list: [],
            imglist: []
        }
    },
    methods: {
        async imglist1() {
            try {
                const { ProductPicture } = await imglist({ productID: this.productID })
                this.imglist = ProductPicture
            } catch (error) { }

        },
        async goodsDetails() {
            try {
                const { Product } = await goodsDetails({ productID: this.productID })
                this.list = Product
                console.log(this.list[0]);
            } catch (error) { }
        },
        async addcat() {
            try {
                let id = this.$store.state.id
                this.$notify({
                    title: '成功',
                    message: '添加商品',
                    type: 'success'
                });
                await addcat({user_id:id,product_id:this.list[0].product_id})
                console.log(id);
                console.log(this.list[0].product_id);
            } catch (error) {

            }
        },
        async like(){
            try {
                let id = this.$store.state.id
               await getlike({product_id:this.list[0].product_id,user_id:id})
               this.$notify({
                    title: '成功',
                    message: '添加收藏成功',
                    type: 'success'
                });
            } catch (error) {
                
            }
        }
    },
    computed: {},
    components: {},
    created() {
        this.goodsDetails();
        this.imglist1();
    },
}
</script>
<style lang="scss" scoped>
.detailsPage {
    width: 100%;

    .top {
        width: 100%;
        display: flex;
        justify-content: space-between;
        line-height: 50px;

        .div {
            width: 200px;
            display: flex;
            justify-content: space-between;

            span:hover {
                color: #ff6700;
                cursor: pointer;
            }
        }
    }

    .center {
        width: 100%;
        height: 560px;
        display: flex;
        margin-top: 20px;

        .left {
            flex: 5;

            .carousel {
                height: 560px;

                .carouselitem {
                    .img {
                        width: 480px;
                        height: 500px;
                        margin: 0 auto;
                        display: block;
                    }
                }
            }
        }

        .right {
            flex: 5;
            padding: 20px;

            .text {
                font-size: 18px;
                margin: 20px 0;
                color: #b0b0b0;
            }

            .p {
                color: #ff6700;
                font-size: 18px;
            }

            .price {
                font-size: 20px;
                line-height: 70px;
                border-bottom: 1px solid #cccccc;

                span {
                    color: #ff6700;
                    margin-right: 10px;
                }

                s {
                    color: #b0b0b0;
                    font-size: 18px;
                }

            }

            .ming {
                width: 100%;
                height: 100px;
                background: #f9f9fa;
                padding: 30px 0;

                .ming-top {
                    display: flex;
                    justify-content: space-between;
                    padding: 0 60px;
                    margin: 30px 0;

                    span {
                        font-size: 18px;
                        color: #796161;
                    }
                }

                .ming-button {
                    padding: 0 60px;
                    color: #ff6700;
                    font-size: 25px;
                }
            }

            .button {
                display: flex;
                justify-content: space-between;
                margin-top: 30px;

                button {
                    width: 45%;
                    border: 0;
                    height: 60px;
                    border-radius: 5px;
                    color: #fff;
                    font-size: 18px;
                }

                .a1 {
                    background: #ff6700;
                }

                .a1:hover {
                    background: #ec5f01;
                }

                .a2:hover {
                    background: #908e8e;
                }

                .a2 {
                    background: #b0b0b0;
                }
            }
        }
    }
}
</style>